package com.hp.tiger.chapter1;

/**
 * @author XavierDong
 **/
public class SingletonObject5 {


    /**
     * 不能保证原子性，可以保证有序性
     * <p>
     * 读的过程 ，必须保证写的过程
     */
    private static volatile SingletonObject5 instance;

    private SingletonObject5() {
        //empty
    }

    /**
     * double check add volatile
     */
    public static SingletonObject5 getInstance() {

        if (null == instance) {
            synchronized (SingletonObject5.class) {
                if (null == instance)
                    instance = new SingletonObject5();
            }
        }
        return SingletonObject5.instance;
    }
}
